import createVitePlugins from './vitePlugins'
import { defineConfig } from 'vite'
import path from 'path'
import { uniPostcssPlugin } from '@dcloudio/uni-cli-shared'

export default defineConfig({
    plugins: [createVitePlugins()],
    css: {
        postcss: {
            plugins: [
                require('postcss-import')({
                    resolve(id: string) {
                        if (id.startsWith('~@/')) {
                            return path.resolve(process.env.UNI_INPUT_DIR as string, id.substr(3))
                        } else if (id.startsWith('@/')) {
                            return path.resolve(process.env.UNI_INPUT_DIR as string, id.substr(2))
                        } else if (id.startsWith('/') && !id.startsWith('//')) {
                            return path.resolve(process.env.UNI_INPUT_DIR as string, id.substr(1))
                        }
                        return id
                    },
                }),
                uniPostcssPlugin(),
                require('tailwindcss')({ config: './tailwind.config.js' }),
                require('autoprefixer')({
                    remove: true,
                }),
            ],
        },
    },
    // #ifdef  H5
    server: {
        proxy: {
            '/api': {
                target: 'http://qd.dev.ithinkdt.com/api/v1',
                // target: 'http://192.168.18.26:30102',
                changeOrigin: true,
                rewrite: path => path.replace(/^\/api/, ''),
            },
        },
    },
    // #endif
})
